define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    // add_url: 'order/add',
                    // edit_url: 'order/edit',
                    // del_url: 'order/del',
                    // multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                exportDataType: 'selected', // basic, all, selected
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'order_sn', title: __('Sn'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.mobile', title: __('User_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'user_level', title: __('User_level')},
                        {field: 'schedule_id', title: __('Schedule_id'),operate:false},
                        {field: 'hall.name', title: __('Hall_id'),operate:false},
                        // {field: 'film.name', title: __('Film_info_id'),operate:false},
                        // {field: 'cinema_name', title: __('Cinema_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'cinema_address', title: __('Cinema_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'total_amount', title: __('Total_amount'), operate:false},
                        {field: 'total_fee', title: __('Total_fee'), operate:false},
                        {field: 'order_amount', title: __('订单金额'), operate:false},
                        {field: 'makeup_price', title: __('妆造金额'), operate:false},
                        {field: 'wine_menu_name', title: __('酒套餐'), operate:false},
                        {field: 'is_ice', title: __('加冰'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.status},
                        {field: 'wine_menu_price', title: __('酒套餐金额'), operate:false},
                        {field: 'start_time', title: __('开始时间'), operate:false},
                        {field: 'make_time', title: __('妆造时间'), operate:false},
                        {field: 'select_seat_str', title: __('所选座位'), operate:false},
                        {field: 'start_time', title: __('开始时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'customer_name', title: __('顾客姓名'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'customer_mobile', title: __('顾客电话'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'after_discount_fee', title: __('After_discount_fee'), operate:false},
                        // {field: 'coupon_id', title: __('Coupon_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'coupon_fee', title: __('Coupon_fee'), operate:false},
                        // {field: 'pay_type', title: __('Pay_type'), searchList: {"wechat":__('Pay_type wechat'),"alipay":__('Pay_type alipay'),"money":__('Pay_type money'),"give_money":__('Pay_type give_money'),"system": __('后台购买'),"cash": __('现金支付'),"adapay_wx_pub": 'adapay微信'}, formatter: Table.api.formatter.normal},
                        {field: 'pay_time', title: __('Pay_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('已退款')}, formatter: Table.api.formatter.status},
                        // {field: 'refund_status', title: __('Refund_status'), searchList: {"-1":__('Refund_status -1'),"0":__('Refund_status 0'),"1":__('Refund_status 1')}, formatter: Table.api.formatter.status},
                        // {field: 'refund_fee', title: __('Refund_fee'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), width: 180, table: table,
                            buttons:[
                                // {
                                //     name:'ticket',
                                //     text:__('打印小票'),
                                //     icon:'fa fa-log',
                                //     classname:'btn btn-xs btn-success btn-dialog',
                                //     extend: 'data-area=\'["80%","60%"]\'',
                                //     // confirm:"点击打印后订单会变成已完成,确定要打印吗？",
                                //     hidden:function (row)
                                //     {
                                //         if(row.status=='-1' || row.status=='0' || row.status=='2' || row.status=='3')
                                //         {
                                //             return true;
                                //         }
                                //     },
                                //     url:function (row,column) {
                                //         return 'ticket/index/?order_id='+row.id
                                //     },
                                //     refresh:true,
                                // },
                                // {
                                //     name:'ticket_complete',
                                //     text:__('出票完成'),
                                //     icon:'fa fa-log',
                                //     classname:'btn btn-xs btn-success btn-ajax',
                                //     extend: 'data-area=\'["80%","80%"]\'',
                                //     confirm:"确定出票已完成",
                                //     hidden:function (row)
                                //     {
                                //         if(row.status=='-1' || row.status=='0' || row.status=='2' || row.status=='3')
                                //         {
                                //             return true;
                                //         }
                                //     },
                                //     url:function (row,column) {
                                //         return '/a.php/order/update_order_status?order_id='+row.id;
                                //     },
                                //     success: function (data, ret) {
                                //         $(".btn-refresh").trigger("click");
                                //         // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                //         //如果需要阻止成功提示，则必须使用return false;
                                //         return false;
                                //     },
                                //     error: function (data, ret) {
                                //         $(".btn-refresh").trigger("click");
                                //         return false;
                                //     },
                                //     refresh:true,
                                // },
                                {
                                    name:'refund',
                                    text:__('锁座退款'),
                                    icon:'fa fa-log',
                                    classname:'btn btn-xs btn-info btn-ajax',
                                    extend: 'data-area=\'["80%","80%"]\'',
                                    confirm:"确认完成订单并退款？",
                                    hidden:function (row)
                                    {
                                        if(row.status=='-1' || row.status=='0' || row.status=='2' || row.status=='3')
                                        {
                                            return true;
                                        }
                                    },
                                    url:function (row,column) {
                                        return '/a.php/order/refund/?order_id='+row.id+'&is_unlock=1';
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        return false;
                                    },
                                    error: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        return false;
                                    },
                                    refresh:true,
                                },
                                {
                                    name:'unLockRefund',
                                    text:__('不锁座退款'),
                                    icon:'fa fa-log',
                                    classname:'btn btn-xs btn-success btn-ajax',
                                    extend: 'data-area=\'["80%","80%"]\'',
                                    confirm:"确认完成订单并退款解锁座位？",
                                    hidden:function (row)
                                    {
                                        if(row.status=='-1' || row.status=='0' || row.status=='2' || row.status=='3')
                                        {
                                            return true;
                                        }
                                    },
                                    url:function (row,column) {
                                        return '/a.php/order/refund/?order_id='+row.id+'&is_unlock=0';
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        return false;
                                    },
                                    error: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        return false;
                                    },
                                    refresh:true,
                                },
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'order/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'order/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'order/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
